#include "AsioWriteBuffer.h"
#include "WriteBuffer.h"

namespace frame {
namespace imp {
namespace asio {

AsioWriteBuffer::AsioWriteBuffer()
:wb(new WriteBuffer)
{
}
AsioWriteBuffer::~AsioWriteBuffer(){
}
void AsioWriteBuffer::pushBack(const std::string & str){
    wb->pushBack(str);
    buffers.emplace_back(boost::asio::buffer(wb->back()));
}
void AsioWriteBuffer::pushBack(std::string && str){
    wb->pushBack(std::move(str));
    buffers.emplace_back(boost::asio::buffer(wb->back()));
}
void AsioWriteBuffer::pushBack(const char * cstr){
    wb->pushBack(cstr);
    buffers.emplace_back(boost::asio::buffer(wb->back()));
}
void AsioWriteBuffer::pushBack(const char * buf, size_t len){
    wb->pushBack(buf, len);
    buffers.emplace_back(boost::asio::buffer(wb->back()));
}
void AsioWriteBuffer::popBack(){
    buffers.pop_back();
    wb->popBack();
}
void AsioWriteBuffer::clear(){
    buffers.clear();
    wb->clear();
}

size_t AsioWriteBuffer::size() const {
    return wb->size();
}

std::ostream & operator<<(std::ostream & os, const AsioWriteBuffer & awb){
    os << "count:" << awb.size() << std::endl;
    for(auto & w : awb){
        os << "    buf_size:" << w.size()  << " data:" << w.data() << std::endl;
    }
    return os;
}

} //end of namespace asio
} //end of namespace imp
} //end of namespace  frame
